package fy.mdm.operator;

import com.seeyon.v3x.services.flow.bean.FlowExport;
import com.seeyon.v3x.services.form.bean.ValueExport;

import fy.form.listen.operate.AForm_Save_Operator;
import fy.form.listen.operate.IFormOperator;
import fy.mdm.bean.NewCustomerCreditBean;
import fy.mdm.dao.FiexdAssetReviewDao;
import fy.mdm.dao.NewCustomerCreditDao;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class NewCustomerCreditOperator extends AForm_Save_Operator implements IFormOperator{
	private NewCustomerCreditBean bean=new NewCustomerCreditBean();
	private static Log log = LogFactory.getLog(FiexdAssetReviewDao.class);
	@Override
	public String getFormName() {
		// TODO Auto-generated method stub

		return "新客户授信";
	}

	@Override
	protected void parseOtherField_FirstStep(FlowExport flowExport) {
		// TODO Auto-generated method stub
		bean.setSummaryId(super.formBean.getSummaryId());
		bean.setBillname(flowExport.getFlowTitle());
		bean.setApplier(flowExport.getFlowCreatePerson().getId());
		bean.setTs(flowExport.getFlowCreateTime());
	}

	@Override
	protected void parseValueExport(ValueExport ve) {

		// TODO Auto-generated method stub
		String fieldName = ve.getDisplayName();
		log.info("fieldName = "+fieldName+"ve.getValue()="+ve.getValue());
		if ("客户全称".equals(fieldName)) {
			bean.setCustomerName(ve.getValue());
		} else if ("客户国别".equals(fieldName)) {
			bean.setCustomerNationality(ve.getValue());
		} else if ("客户属性".equals(fieldName)) {
			bean.setCustomerAttribute(ve.getValue());
		} else if ("客户系别".equals(fieldName)) {
			bean.setAccountType(ve.getValue());
		} else if ("客户大类".equals(fieldName)) {
			bean.setCustomerType(ve.getValue());
			log.info(ve.getDisplayValue());
		} else if ("信用期申请".equals(fieldName)) {
			bean.setCreditDays(ve.getValue());
		} else if ("结算方式".equals(fieldName)) {
			bean.setSettlementMethod(ve.getValue());
		}else if ("是否退税".equals(fieldName)) {
			bean.setTaxRebates(ve.getValue());
		}else if("客户编码".equals(fieldName)){
			bean.setCUSTOME_CODE(ve.getValue());
		}
	}

	@Override
	protected boolean save() {
		// TODO Auto-generated method stub
		try {
			NewCustomerCreditDao NewCustomerCreditDao =new NewCustomerCreditDao();
			NewCustomerCreditDao.setNewCustomerCreditBean(bean);		
			return NewCustomerCreditDao.getStateReturn();
		} catch (Exception e) {
			// TODO: handle exception
		}finally {
			//bean.clear();
			bean = null;
		}
	return success;

	}

}
